#include "dialog.h"
#include <QColorDialog>

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{
    fileBtn=new QPushButton(tr("file dialog"));
    fileLineEdit=new QLineEdit();
    mainlayout=new QGridLayout(this);
    mainlayout->addWidget(fileLineEdit,0,0);
    mainlayout->addWidget(fileLineEdit,0,1);
    connect(fileBtn,SIGNAL(clicked(bool)),this,SLOT(showfile()));

    colorBtn=new QPushButton(tr("color dialog"));
    colorFrame=new QFrame;
    colorFrame->setFrameStyle(QFrame::Box);
    colorFrame->setAutoFillBackground(true);
    mainlayout->addWidget(colorBtn,1,0);
    mainlayout->addWidget(colorFrame,1,1);
    connect(colorBtn,SIGNAL(clicked(bool)),this, SLOT(showcolor()));

    fontBtn=new QPushButton(tr("word stely"));
    frontLineEdit=new QLineEdit;
    mainlayout->addWidget(fontBtn,2,0);
    mainlayout->addWidget(fontLineEdit,2,1);
    connect(fontBtn,SIGNAL(clicked()),this, SLOT(showFont()));


}


void Dialog::showfile()
{
   QString s=QFileDialog::getOpenFileName(this,"open file dialog", "/",
                                          "C++ files(*.cpp);;Cfiles(*.c);;Headfiles(*.h)");
   fileLineEdit->setText(s);
}

void Dialog::showcolor()
{
    QColor c=QColorDialog::getColor(Qt::bule);
    if(c.isValid())
    {
        colorFrame->setPalette(QPalette(c));
    }

}

void Dialog::showFont()
{
   bool ok;
   QFont f=QFontDialog::getFont(&ok);
   if(ok)
   {
       fontLineEdit->setFont(f);
   }
}

Dialog::~Dialog()
{

}
